package com.aaa.controller;

import com.aaa.entity.Melody;
import com.aaa.service.PreferService;
import com.aaa.util.DefaultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Prefer")
public class PreferController {

    @Autowired
    private PreferService preferService;


    @RequestMapping("/listMyPrefer")
    public List<Melody> listAll(String pramykey, Authentication authentication){
        Object principal = authentication.getPrincipal();
        List<Melody> melodies = preferService.listAllMelody(pramykey,String.valueOf(principal));
        return melodies;
    }

    @RequestMapping("/PreferLoad")
    public List<Melody> PreferLoad(String mid){
        List<Melody> melodies = preferService.PreferLoad(Integer.valueOf(mid));
        return melodies;
    }

    @RequestMapping("/clickOn")
    public DefaultMsg clickOn(String mid,Authentication authentication){
        String principal = (String) authentication.getPrincipal();
        DefaultMsg defaultMsg = preferService.clickOn(mid, principal);
        return defaultMsg;
    }

    @RequestMapping("/clickMV")
    public Melody clickMV(String mid){
        Melody melody = preferService.clickMV(mid);
        return melody;
    }

    @RequestMapping("/discuss")
    public Melody discuss(String mid){
        Melody melody = preferService.clickMV(mid);
        return melody;
    }
}
